package com.lck.blogmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.entity.UserEntity;
import com.lck.blogmanager.req.ChangeUserStatusReq;
import com.lck.blogmanager.req.UserInfoPageReq;
import com.lck.blogmanager.res.UserInfoPageRes;
import com.lck.blogmanager.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/10 20:17
 */
@CrossOrigin
@RequiredArgsConstructor
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    private final UserService userService;

    /**
     * 管理端用户列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<UserInfoPageRes>> userInfoPage(@RequestBody UserInfoPageReq req){
        Page<UserInfoPageRes> res = userService.userInfoPage(req);
        return Response.success(res);
    }

    /**
     * 用户详细信息
     * @param userId
     * @return
     */
    @GetMapping("/detail/{userId}")
    public Response<UserEntity> getUserDetail(@PathVariable Integer userId){
        UserEntity entity = userService.getUserDetail(userId);
        return Response.success(entity);
    }


    /**
     * 切换用户状态
     * @param req
     * @return
     */
    @PostMapping("/changeUserStatus")
    public Response changeUserStatus(@RequestBody ChangeUserStatusReq req){
        userService.changeUserStatus(req);
        return Response.success();
    }

    /**
     * 重置用户密码
     * @param userId
     * @return
     */
    @GetMapping("/resetPassword/{userId}")
    public Response resetPassword(@PathVariable Integer userId){
        userService.resetPassword(userId);
        return Response.success();
    }

}
